package com.eshop.eshop2021_v1.serviceImpl;

import com.eshop.eshop2021_v1.common.JsonResult;
import com.eshop.eshop2021_v1.mapper.before.FocusMapper;
import com.eshop.eshop2021_v1.pojo.Focus;
import com.eshop.eshop2021_v1.pojo.User;
import com.eshop.eshop2021_v1.service.FocusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: 若若叶
 * @date: 2021/10/12 11:06 FileName: FocusServiceImpl Description:
 */
@Service
public class FocusServiceImpl implements FocusService {
  @Autowired private FocusMapper focusMapper;
  List a = new ArrayList();

  @Override
  public JsonResult addFocus(Integer goodId, HttpSession session) {

    if (null == goodId) {
      return new JsonResult(201, "商品下架", null);
    }
    User loginUser = (User) session.getAttribute("loginUser");
    if (null == loginUser) {
      return new JsonResult(202, "会话过期", null);
    }
    Focus focus = new Focus();
    focus.setUserId(loginUser.getUid());
    focus.setGoodId(goodId);
    int row = focusMapper.addFocus(focus);
    if (row != 1) {
      return new JsonResult(203, "收藏失败，请重试", null);
    }
    return new JsonResult(200, "收藏成功", null);
  }
}
